﻿namespace MoreExtentions
{
    public static partial class Linq
    {
        /// <summary>
        /// Gets the most inner (deepest) exception of a given Exception object
        /// </summary>
        /// <param name="ex">Source Exception</param>
        /// <returns></returns>
        public static System.Exception GetMostInnerException(this System.Exception ex)
        {
            System.Exception ActualInnerEx = ex;
            while (ActualInnerEx != null)
            {
                ex = ActualInnerEx;
                ActualInnerEx = ActualInnerEx.InnerException;
            }
            return ex;
        }
    }
}